import { createSSRApp, createApp } from "vue";
import { createPinia } from "pinia";
import App from "./App.vue";
import { createDefaultRouter } from "./router";
import { initConfig } from "./config";
// import ViewUIPlus from "view-ui-plus";
import { pinia } from "./libs/pinia";

export async function createMainApp(BUILD_CONFIG: Record<string, any>, ssrUrl?: string) {
	await initConfig(BUILD_CONFIG);

	// 修复导入错误
	// const ViewUIPlus = await (import.meta.env.SSR ? import("view-ui-plus") : import("view-ui-plus/dist/viewuiplus.min.esm.js"));

	const router = createDefaultRouter();
	if (ssrUrl) {
		console.log("create app route: ", router.currentRoute);
		await router.replace(ssrUrl);
	}

	const app = createSSRApp(App)
		// const app = createApp(App)
		// .use(vuePluginI18n)
		// .use(ViewUIPlus, {
		// i18n: vuePluginI18n,
		// })
		.use(pinia)
		.use(router);

	return { app, pinia, router };
}
